package stack.be.touch.dao;

import stack.be.touch.dto.SiteDTO;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;

public class SiteDAO extends BaseDAO<SiteDTO> {
	
	public SiteDAO(Context context) {
		super(context);
	}

	public long addSite(SiteDTO site) {
		ContentValues cv = new ContentValues();
		cv.put(SiteDTO.KEY_ENDPOINT, site.getEndpoint());
		cv.put(SiteDTO.KEY_NAME, site.getName());
		cv.put(SiteDTO.KEY_UID, site.getUserID());
		cv.put(SiteDTO.KEY_POS, site.getPosition());
		cv.put(SiteDTO.KEY_CHECKED, site.isChecked());
		cv.put(SiteDTO.KEY_UNAME, site.getUname());

		return super.add(cv,SiteDTO.TABLE_NAME);

	}

//	public int removeSite(MySite site) {
//		ContentValues cv = new ContentValues();
//		cv.put(MySite.KEY_ENDPOINT, site.getEndpoint());
//		return super.remove(MySite.TABLE_NAME, site.getEndpoint());
//	}
	
	public int removeSite(SiteDTO site) {
		ContentValues cv = new ContentValues();
		cv.put(SiteDTO.KEY_ENDPOINT, site.getEndpoint());
		return super.remove(SiteDTO.TABLE_NAME, cv);
	}
	
	public void removeAllSites() {
		super.removeAll(SiteDTO.TABLE_NAME);
	}

	public Cursor getMySites(String TableName) {
		return super.getAll(TableName);
	}
	
	public String getEndpoint(Cursor c) {
		return c.getString(c.getColumnIndex(SiteDTO.KEY_ENDPOINT));
	}
	public String getName(Cursor c) {
		return c.getString(c.getColumnIndex(SiteDTO.KEY_NAME));
	}
	public int getReputation(Cursor c) {
		return c.getInt(c.getColumnIndex(SiteDTO.KEY_REPUTATION));
	}
	public String getUserName(Cursor c) {
		return c.getString(c.getColumnIndex(SiteDTO.KEY_UNAME));
	}
	public int getUserID(Cursor c) {
		return c.getInt(c.getColumnIndex(SiteDTO.KEY_UID));
	}
	
	public int getChecked(Cursor c) {
		return c.getInt(c.getColumnIndex(SiteDTO.KEY_CHECKED));
	}
	
	public int getPosition(Cursor c) {
		return c.getInt(c.getColumnIndex(SiteDTO.KEY_POS));
	}

}
